/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.statementView;
/**
 * 说明：
 * 利润报表
 * @Author：
 * @Date：2012-03-21
 */
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.ruipengkj.component.jlist.ListButtonCellRenderer;
import com.ruipengkj.component.jlist.ListNodeButton;
import com.ruipengkj.component.jlist.StatementListPanel;
import com.ruipengkj.view.base.BasePanel;

public class StatementProfitPanel extends BasePanel implements ListSelectionListener {
	private static final long serialVersionUID = 1L;
	
	private StatementProfitCommodity statementProfitCommodity;//商品毛利润表显示按钮
	private StatementBusinessPerformance statementBusinessPerformance;//经营业绩表
	private StatementSurplusCommodity statementSurplusCommodity;//盈余表
	private StatementLossCommodity statementLossCommodity;//亏损表
	
	private CardLayout right_layout;
	private JPanel right_panel;
	private DefaultListModel listModel;
	private JList btnList;//功能按钮列表
	
	public StatementProfitPanel() {
		this.setLayout(new BorderLayout());
		this.init();
	}
	//create view ruipengkj_surplus_order_summary as select o.orderid,o.HappenTime as addTime,sum(b.num) as totalNum,sum(b.num*b.price) as totlePrice ,(sum(b.price*b.num)-sum(o.avgPrice*b.num)) as surplus from ruipeng_tb_torder as o,ruipeng_tb_tbilldetail as b where o.orderid=b.billid and b.billType = 3 group by o.orderid;

	private void init() {
		listModel=new DefaultListModel();
		listModel.addElement(new ListNodeButton("商品毛利润表"));
		listModel.addElement(new ListNodeButton("经营业绩表"));
		listModel.addElement(new ListNodeButton("盈利单汇总表"));
		listModel.addElement(new ListNodeButton("亏损单汇总表"));
		btnList=new StatementListPanel();
		btnList.setFixedCellHeight(35);
		btnList.setModel(listModel);
		btnList.setCellRenderer(new ListButtonCellRenderer());
		btnList.addListSelectionListener(this);
		btnList.setBackground(new Color(245, 250, 255));
		JSplitPane jsp = new JSplitPane();
		jsp.add(btnList, JSplitPane.LEFT, 0);
		jsp.add(initRight(), JSplitPane.RIGHT, 0);
		jsp.setDividerLocation(180);
		this.add(uiFactory.createFlowJPanel(), BorderLayout.SOUTH);
		this.add(jsp, BorderLayout.CENTER);
	}
	
	private JPanel initRight() {
		right_layout = new CardLayout();
		right_panel = new JPanel(right_layout);
		
		statementProfitCommodity = new StatementProfitCommodity();
		right_panel.add(statementProfitCommodity, "a");
		right_layout.show(right_panel, "a");
		SwingUtilities.invokeLater(statementProfitCommodity);
		return right_panel;
	}
	
	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void valueChanged(ListSelectionEvent e) {
		switch (btnList.getSelectedIndex()) {
		case 0: {
			// 商品毛利润表
			statementProfitCommodity = new StatementProfitCommodity();
			right_panel.add(statementProfitCommodity, "a");
			right_layout.show(right_panel, "a");
			SwingUtilities.invokeLater(statementProfitCommodity);
			break;
		}
		case 1: {
			// 经营业绩表
			statementBusinessPerformance = new StatementBusinessPerformance();
			right_panel.add(statementBusinessPerformance, "b");
			right_layout.show(right_panel, "b");
			SwingUtilities.invokeLater(statementBusinessPerformance);
			break;
		}
		case 2: {

		// 盈利单汇总
		statementSurplusCommodity = new StatementSurplusCommodity();
		right_panel.add(statementSurplusCommodity, "c");
		right_layout.show(right_panel, "c");
		SwingUtilities.invokeLater(statementSurplusCommodity);
		break;
		}
		case 3:{
		// 盈利单汇总
		statementLossCommodity = new StatementLossCommodity();
		right_panel.add(statementLossCommodity, "d");
		right_layout.show(right_panel, "d");
		SwingUtilities.invokeLater(statementLossCommodity);
		break;
		}
		}
	}
}
